package com.woniuxy.microwalletserver.controller;

import com.alibaba.fastjson.JSONObject;
import com.woniuxy.bean.BillBean;
import com.woniuxy.bean.ResultBean;
import com.woniuxy.microwalletserver.bean.SearchBean;
import com.woniuxy.microwalletserver.service.IBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: masterhai
 * @date: 2021/4/14:20:00
 * @description:
 */
@RefreshScope
@Api("账单对应操作功能接口")
@RestController
@RequestMapping(value = "/bill", produces = {"application/json;charset=utf-8"})
public class BillOperationController {
    @Resource
    private IBillService billService;

    //生成交易记录
    @ApiOperation("生成交易记录数据并插入数据库接口,不需要测试,内部调用")
    @PostMapping("createFakeOrder")
    public ResultBean createFakeOrder (@RequestBody BillBean billBean) {
        if (ObjectUtils.isEmpty(billBean)) {
            return ResultBean.ParamError();
        }
        if (StringUtils.isEmpty(billBean.getCouponName())) {
            billBean.setCouponName("");
        }
        if (StringUtils.isEmpty(billBean.getPayType())) {

        }
        BillBean fakeBill = billService.createFakeOrder(billBean);
        return ResultBean.builder().code(200).msg("生成交易记录数据并插入数据库成功").data(fakeBill).build();
    }

    @ApiOperation("根据账号查询最新账单")
    @PostMapping("selectNewOrder")
    public List<BillBean> selectNewOrder (@RequestBody BillBean billBean) {
        System.out.println("查询对象:" + billBean);
        return billService.selectNewOrder(billBean);
    }

    //获取课程活动统计信息
    @ApiOperation("查询理财产品收益信息")
    @PostMapping("getEarningsInfo")
    public ResultBean getEarningsInfo (@RequestBody SearchBean searchBean) {
        System.out.println("查询对象:" + searchBean);
        if (searchBean != null && StringUtils.isEmpty(searchBean.getType())) {
            return ResultBean.builder().code(777).msg("查询类型不能为空").build();
        }
        HashMap<String, Object> maps = billService.getEarningsInfo(searchBean.getType(), searchBean.getBegin(), searchBean.getEnd());
        System.out.println("map:" + maps);
        return ResultBean.builder().code(200).msg("查询成功").data(maps).build();
    }
}
